/**
 * Token.js
 * Classe que define tokens
 *
 * Andrei de A. Formiga, 2008-07-06
 *
 */

// Construtor
function Token(type, value)
{
  this.type = type;
  this.value = value;
}

// Constantes para tipos de tokens
Token.ID      = 0;
Token.NUMBER  = 1;
Token.STRING  = 2;
Token.KEYWORD = 3;
Token.PUNCT   = 4;
Token.EOF     = 200;

// Objeto que representa o fim da entrada
Token.eof = new Token(Token.EOF, null);

// metodo toString()
Token.prototype.toString =
  function()
  {
    return "<" + typeStr(this.type) + ", " + this.value.toString() + ">";
  };

function typeStr(type)
{
  var result = "unknown";

  switch (type)
  {
  case Token.ID:
    result = "id";
    break;

  case Token.NUMBER:
    result = "num";
    break;

  case Token.STRING:
    result = "string";
    break;

  case Token.KEYWORD:
    result = "keyword";
    break;

  case Token.PUNCT:
    result = "punct";
    break;

  case Token.EOF:
    result = "EOF";
    break;
  }

  return result;
}
